# -*- coding:utf-8 -*-
# 2022/1/24 10:03
# author:xwl
from fastapi import APIRouter, Depends

from backend.app.app.api.api_Xiong.crud.pri_crud import read_stimeval_cal_result_func, \
    unit_scheme_curve_delete_data
from backend.app.app.api.api_Xiong.crud.pub_crud import get_all_proj_name_by_tydoper, get_dvpname_inf, \
    unit_scheme_curve_readdb_fun, eva_cal_output_save
from backend.app.app.api.api_Xiong.models.x_model import unit_scheme_curve_readdb, eva_cal_out_save
from backend.app.app.api.api_v1.user import verify_token_user

unit_scheme_curve = APIRouter(prefix="/unit_scheme_curve", tags=["单元方案曲线"])


@unit_scheme_curve.post("/get_proj_name", name="获取数据筛选条件1")
async def get_proj_name(ver=Depends(verify_token_user)):
    result = get_all_proj_name_by_tydoper()
    return {
        "result": result,
        'verify': ver
    }


@unit_scheme_curve.post("/get_dvpinfo_by_projname", name="获取数据筛选条件2")
async def get_dvpinfo_by_projname(DvpUnit_OilStim_PlanProj_Name: str,ver=Depends(verify_token_user)):
    result = get_dvpname_inf(DvpUnit_OilStim_PlanProj_Name)
    return {
        "result": result,
        'verify': ver
    }


@unit_scheme_curve.post("/readdb", name="读库")
async def readdb(datas: unit_scheme_curve_readdb, ver=Depends(verify_token_user)):
    result = unit_scheme_curve_readdb_fun(
        datas.DvpUnit_Name, datas.StimType_Name, datas.Year)
    return {
        'result': result,
        'verify': ver
    }


@unit_scheme_curve.post("/read_stimeval-cal_result", name="读取评价计算结果")
async def read_stimeval_cal_result(ver=Depends(verify_token_user)):
    result = read_stimeval_cal_result_func()
    return {
        'result': result,
        'verify': ver
    }


@unit_scheme_curve.post("/save", name="存库")
async def save(data: eva_cal_out_save, ver=Depends(verify_token_user)):
    result = eva_cal_output_save(data.datas)
    delete_result = unit_scheme_curve_delete_data(data.delete)
    return {
        'result': result,
        'delete_result': delete_result,
        'verify': ver
    }
